package com.ruoyi.project.inventory.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.warehouse.domain.RyDepot;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.inventory.domain.RyInventory;
import com.ruoyi.project.inventory.service.IRyInventoryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 物品信息Controller
 *
 * @author you
 * @date 2022-09-05
 */
@RestController
@RequestMapping("/inventory/RyInventory")
public class RyInventoryController extends BaseController
{
    @Autowired
    private IRyInventoryService ryInventoryService;


    /**
     * 查询所有仓库列表
     */
    @GetMapping("/all")
    public AjaxResult all()
    {
//        startPage();
        List<RyInventory> list = ryInventoryService.all();
        for(RyInventory ryInventory : list){
            ryInventory.setLabel(ryInventory.getName() + " | " + ryInventory.getSpecifications());
        }
        return AjaxResult.success(list);
    }

    /**
     *根据规格编码查询所有物品信息
     */
    @GetMapping("/specifications/{specifications}")
    public AjaxResult speciFicationInFor(@PathVariable String specifications){
        System.out.println(specifications);
        RyInventory ry=ryInventoryService.selectRyInventorySpeciInFor(specifications);
        System.out.println(ry);
        return AjaxResult.success(ry);
    }

    /**
     * 查询物品信息列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:RyInventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(RyInventory ryInventory)
    {
        startPage();
        List<RyInventory> list = ryInventoryService.selectRyInventoryList(ryInventory);
        return getDataTable(list);
    }

    /**
     * 导出物品信息列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:RyInventory:export')")
    @Log(title = "物品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RyInventory ryInventory)
    {
        List<RyInventory> list = ryInventoryService.selectRyInventoryList(ryInventory);
        ExcelUtil<RyInventory> util = new ExcelUtil<RyInventory>(RyInventory.class);
        util.exportExcel(response, list, "物品信息数据");
    }

    /**
     * 获取物品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:RyInventory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ryInventoryService.selectRyInventoryById(id));
    }

    /**
     * 新增物品信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:RyInventory:add')")
    @Log(title = "物品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RyInventory ryInventory)
    {
        return toAjax(ryInventoryService.insertRyInventory(ryInventory));
    }

    /**
     * 修改物品信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:RyInventory:edit')")
    @Log(title = "物品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RyInventory ryInventory)
    {
        return toAjax(ryInventoryService.updateRyInventory(ryInventory));
    }

    /**
     * 删除物品信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:RyInventory:remove')")
    @Log(title = "物品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ryInventoryService.deleteRyInventoryByIds(ids));
    }
}
